package com.rk.kbk.controller;

import com.rk.kbk.common.JsonResp;
import com.rk.kbk.dao.InsuranceDao;
import com.rk.kbk.model.Insurance;
import com.rk.kbk.model.SellerWithdraw;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * Created by bilibili on 2017/4/27.
 */
@CrossOrigin
@RestController
@Transactional
@RequestMapping(value="/api/insurance")
public class InsuranceController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private InsuranceDao insuranceDao;


    /**
     * @添加/修改
     * @param insurance
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/addOrUpdateInsurance",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp addOrUpdateInsurance(@RequestBody Insurance insurance){
        log.debug("添加/修改");
        insuranceDao.save(insurance);
        return JsonResp.ok(insurance);
    }

    /**
     * @获取详情
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/insuranceDetails",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp insuranceDetails() {
        log.debug("获取详情");
        return JsonResp.ok(insuranceDao.findAll());
    }
}
